
import random
from program.python.Lesson1.Title2.pojo.Jinx import Jinx
from program.python.Lesson1.Title2.pojo.Timo import Timo

#以 utf-8 的编码格式打开指定文件
file_Jinx = open("Data/Attribute/Jinx",encoding = "utf-8")
file_Timo = open("Data/Attribute/Timo",encoding = "utf-8")
file_timo_temp = file_Timo.readlines()
file_jinx_temp = file_Jinx.readlines()
#获取文件中的数据，用变量引用实体类
timo = Timo(int(file_timo_temp[0]), int(file_timo_temp[1]))
jinx = Jinx(int(file_jinx_temp[0]), int(file_jinx_temp[1]))

#关闭文件
file_Jinx.close()

f = True;
n = 1
Timo_score = 0
Jinx_score = 0
while f:
    for i in range(1, 4):
        print(' \n——————现在是第 {} 局——————'.format(n))

        # 初始化血量
        timo.reset1()
        jinx.reset1()

        # 打印战果
        while timo.hp > 0 and jinx.hp > 0:
            # 重置Timo攻击
            timo.reset2()
            jinx.reset2()
            # 百分之20触发Timo概率技能
            if random.randint(1, 5) == 4:
                timo.Jn()
                print('Timo触发了技能，伤害+2')
            # 百分之20触发Jinx技能
            if random.randint(1, 5) == 4:
                jinx.Jn()
                print('Jinx触发了技能，血量+6')

            timo.fight(jinx.hp, jinx.power)
            jinx.fight(timo.hp, timo.power)
            print('Timo发起了攻击，【Jinx】剩余血量{}'.format(jinx.hp))
            print('Jinx发起了攻击，【Timo】的血量剩余{}'.format(timo.hp))
            print('------------------------')

        if timo.hp > 0 and jinx.hp <= 0:
            print('Jinx凉了，Timo获胜！')
            Timo_score += 1
            n += 1
        elif timo.hp <= 0 and jinx.hp > 0:
            print('悲催，Jinx把Timo干掉了...')
            Jinx_score += 1
            n += 1
        else:
            print('哎呀，Jinx和Timo同归于尽了~')

        print(Timo_score, Jinx_score)
        # 判断三局两胜的胜负者
        # 判断胜利二场，并且
        if Timo_score == 2 or Jinx_score == 2:
            if (Timo_score > Jinx_score):
                print('最终获胜者是Timo！')
                f = False
                break
            elif Jinx_score > Timo_score:
                print('Timo最终输掉了比赛...')
                f = False
                break
            else:
                print('Timo和Jinx果然是平分秋色')
                f = False
                break

